import { Alova } from '@/utils/http/alova';
import { Device } from '@/api/analysis/device';
import { Algorithm } from '@/api/analysis/algorithm';

export interface VideoTask {
  id: number;
  name: string;
  status: number;
  device_id: string;
  algorithm_ids: number[];
  rtsp_url: string;
  task_type: string;
  task_mode: string;
}
// 获取分组列表
export async function CreateTask(task: VideoTask) {
  return Alova.Post<VideoTask>('/task/create', {
    task,
  });
}

// 获取分组列表
export interface TaskListResponse {
  list: VideoTask[];
  total: number;
  page: number;
  pageSize: number;
}

export interface PaginationParams {
  page?: number;
  pageSize?: number;
  keyword?: string;
}

export async function FetchTaskList(params?: PaginationParams) {
  return Alova.Get<TaskListResponse>('/task/list', {
    params: {
      page: params?.page || 1,
      pageSize: params?.pageSize || 10,
      keyword: params?.keyword || '',
    },
  });
}

export async function UpdateTaskStatus(id: number, status: string) {
  return Alova.Post('/task/update/' + id, {
    status,
  });
}

export async function DeleteTask(id: number) {
  return Alova.Post('/task/delete', {
    id,
  });
}

/**
 * @description: 获取算法列表
 * @param params 分页参数
 * @returns 包含算法列表和总数的响应对象
 */
export function FetchAlgorithmList() {
  return Alova.Get<Algorithm[]>('/algorithm/list', {
    params: {
      isInstalled: true,
    },
  });
}

export function FetchDeviceList() {
  return Alova.Get<Device[]>('/device/list');
}
